package com.zb.entity.dto;

import com.zb.entity.ZjAdmVersion;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.math.BigDecimal;
import java.util.List;

/**
 * @Author WEN
 * @Date 2023/7/13 0013
 **/
@Data
@ApiModel("版本实体")
public class VersionDto {
    @ApiModelProperty(value = "主健ID，新增时不传，修改时必传")
    private Long id;

    @NotBlank(message = "版本名称不能为空")
    @Length(max = 10, message = "版本名称字符长度限制在10个以内")
    @ApiModelProperty(value = "版本名称", required = true)
    private String name;

    @ApiModelProperty(value = "是否工单无限制：false-否，true-是", required = true)
    private Boolean orderUnlimited = false;

    @ApiModelProperty(value = "工单限制数")
    private Integer orderLimitNum;

    @NotNull(message = "用户数不能为空")
    @ApiModelProperty(value = "用户数", required = true)
    private Integer userQty;


    @NotNull(message = "单价类型不能为空")
    @ApiModelProperty(value = "单价类型：1-月，2-季度，3-年", required = true)
    private Integer type;

    @NotNull(message = "单价不能为空")
    @ApiModelProperty(value = "单价", required = true)
    private BigDecimal price;


    @Size(min = 1, message = "功能模块至少要选一项")
    @ApiModelProperty(value = "功能模块ID集合", required = true)
    private List<Long> moduleIds;

    public static VersionDto beanToDto(ZjAdmVersion version, List<Long> moduleIds) {
        VersionDto dto = new VersionDto();
        BeanUtils.copyProperties(version, dto);
        dto.setModuleIds(moduleIds);
        return dto;
    }
}
